package com.example.controller;

import com.example.common.Result;
import com.example.entity.Address;
import com.example.entity.LikeUser;
import com.example.entity.Post;
import com.example.service.LikeUserService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(value = "收藏的帖子与用户关注", tags = {"收藏的帖子与用户关注的增删查"})
@RequestMapping("/likeUser")
public class LikeUserController
{

    @Resource
    private LikeUserService likeUserService;
    /**
     * 新增
     */
    @ApiOperation(value = "增加关注的用户(只填uid与likeid)", notes = "返回是否成功")
    @PostMapping("/add")
    public Result add(@RequestBody LikeUser likeUser) {
        likeUserService.add(likeUser);
        return Result.success();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "取消关注用户(只填uid与likeid)", notes = "返回是否成功")
    @DeleteMapping("/delete")
    public Result deleteById(@RequestBody LikeUser likeUser) {
        likeUserService.deleteById(likeUser);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @ApiIgnore
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        likeUserService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     */
    @ApiIgnore
    @PutMapping("/update")
    public Result updateById(@RequestBody LikeUser likeUser) {
        likeUserService.updateById(likeUser);
        return Result.success();
    }

    /**
     * 根据ID查询
     */
    @ApiIgnore
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        LikeUser likeUser = likeUserService.selectById(id);
        return Result.success(likeUser);
    }

    /**
     * 查询所有
     */
    @ApiOperation(value = "查询所有符合特征的收藏的帖子与用户关注", notes = "返回Models中的收藏的帖子与用户关注的数组")
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功", response =LikeUser.class,reference = "LikeUser")
    })
    @GetMapping("/selectAll")
    public Result selectAll( LikeUser likeUser) {
        List<LikeUser> userList = likeUserService.selectAll(likeUser);
        return Result.success(userList);
    }

    /**
     * 分页查询
     */
    @ApiIgnore
    @GetMapping("/selectPage")
    public Result selectPage(LikeUser likeUser,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<LikeUser> pageInfo = likeUserService.selectPage(likeUser, pageNum, pageSize);
        return Result.success(pageInfo);
    }
    @ApiIgnore
    @GetMapping("/selectPostPage")
    public Result selectPostPage(LikeUser likeUser,
                                 @RequestParam(defaultValue = "1") Integer pageNum,
                                 @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Post> pageInfo = likeUserService.selectPostPage(likeUser, pageNum, pageSize);
        return Result.success(pageInfo);
    }
}
